﻿using UnityEngine;

public enum DialogType
{
    None,
    Nomal,
    Single,
}

public class DialogBaseView
{
    public DialogBasePanel dialogBase;
    private Vector3 dialogBtnPos = Vector3.zero;
    private UILabel[] dialogTxts = new UILabel[2];

    public void Init(GameObject Go)
    {
        dialogBase = new DialogBasePanel(Go);
        dialogBtnPos = dialogBase.Dialog1_obj.transform.localPosition;
        dialogTxts[0] = dialogBase.Dialog1_txt; dialogTxts[1] = dialogBase.Dialog2_txt;
    }

    public void Refresh(ObjData dialogData)
    {
        var table_GlobalDialog = TableDataMgr.GlobalDialogMgr.GetItemById(dialogData.objId);
        if (table_GlobalDialog == null) { return; }
        for (int i = 0; i < table_GlobalDialog.GetBtnNameCount(); i++)
        {
            if (i >= dialogTxts.Length) { break; }
            int id = table_GlobalDialog.GetBtnNamebyIndex(i);
            dialogTxts[i].text = DBSystemMgr.GetSingleton().GetStringByID(id);
        }

        dialogBase.Tip_txt.text = DBSystemMgr.GetSingleton().GetStringByID(table_GlobalDialog.Title);
        dialogBase.Info_txt.text = DBSystemMgr.GetSingleton().GetStringByID(table_GlobalDialog.ContentId, dialogData.strArg);
        Utility.SetActive(dialogBase.Close_obj, table_GlobalDialog.TapClose);

        DialogType type = (DialogType)table_GlobalDialog.TipType;
        if (type == DialogType.Nomal)
        {
            dialogBase.Dialog1_obj.transform.localPosition = dialogBtnPos;
            Utility.SetActive(dialogBase.Dialog2_obj, true);
        }
        else if (type == DialogType.Single)
        {
            Vector3 pos = new Vector3(0, dialogBtnPos.y, 0);
            dialogBase.Dialog1_obj.transform.localPosition = pos;
            Utility.SetActive(dialogBase.Dialog2_obj, false);
        }
        else
        {
            dialogBase.Dialog1_obj.transform.localPosition = dialogBtnPos;
            Utility.SetActive(dialogBase.Dialog1_obj, false);
            Utility.SetActive(dialogBase.Dialog2_obj, false);
        }
    }
    
    public void Clear()
    {
        dialogTxts = null;
        dialogBase = null;
    }
}